package com.bdqn.t350.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;


@Controller
@RequestMapping(path = "/hr")
public class HelloController {
    @RequestMapping(path = "/hello")
    protected String hello(Model model) {
        System.out.println("SpringMVC 我来了");
        model.addAttribute("name", "zhangsan");
        return "hello";
    }

    @RequestMapping(value = "/hello1")
    protected String hello1(Model model, @RequestParam String name, HttpServletRequest request, HttpServletResponse response) {
        System.out.println("SpringMVC1 我来了");
        model.addAttribute("name", name);
        request.setAttribute("name1",name);
        HttpSession session = request.getSession();
        session.setAttribute("sessionName",name);
        return "hello";
    }

    @RequestMapping(value = "/list")
    protected String list(Model model) {
        System.out.println("list 我来了");
        List<String> list = new ArrayList<>();
        list.add("aa");
        list.add("bb");
        list.add("cc");
        model.addAttribute("list", list);
        return "list";
    }
}
